package qc.module.platform.api.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import qc.module.platform.dto.config.ConfigDto;
import qc.module.platform.dto.config.ConfigQueryConditionDto;
import qc.module.platform.dto.project.ProjectDto;
import qc.module.platform.service.ProjectConfigsService;
import qc.module.platform.service.ProjectService;

import java.util.List;

/**
 * 项目及配置信息查询Controller
 * 用于获取项目基本信息，查询项目配置信息，仅用于查询，项目管理和配置管理有另外的Controller
 *
 * @author QuCheng Tech
 * @create 2023/1/9
 */
@RestController
@RequestMapping("/cfg")
public class ProjectConfigController {
    private ProjectService projectService;
    private ProjectConfigsService projectConfigsService;

    @Autowired
    public void setProjectService(ProjectService projectService) {
        this.projectService = projectService;
    }

    @Autowired
    public void setProjectConfigsService(ProjectConfigsService projectConfigsService) {
        this.projectConfigsService = projectConfigsService;
    }

    /**
     * 根据项目编号获取项目信息,项目状态必须为启用
     *
     * @param id 项目编码
     * @return ProjectDto对象
     * @author QcCheng Tech
     * @since 2023/2/7
     */
    @GetMapping("/project")
    public ProjectDto getProject(@RequestParam(required = true) String id) {
        return projectService.get(id, true);
    }

    /**
     * 根据传入对象查询配置信息，项目状态和配置信息状态必须为启用
     *
     * @param dto ConfigQueryConditionDto
     * @return 配置信息集合
     * @author QcCheng Tech
     * @since 2023/2/7
     */
    //不能多次指定Mapping，多次指定以第一次指定为准
    //@GetMapping("/groupconfigs")
    //@PostMapping("/groupconfigs")
    @RequestMapping(value = "/groupconfigs", method = {RequestMethod.GET, RequestMethod.POST})
    public List<ConfigDto> getGroupConfigs(@RequestBody ConfigQueryConditionDto dto) throws Exception {
        return projectConfigsService.query(dto, true);
    }

    /**
     * 根据传入对象查询指定信息
     *
     * @param dto ConfigQueryConditionDto
     * @return 配置信息dto对象
     * @author QcCheng Tech
     * @since 2023/2/7
     */
    @RequestMapping(value = "/config", method = {RequestMethod.GET, RequestMethod.POST})
    public ConfigDto getConfigInfo(@RequestBody ConfigQueryConditionDto dto) throws Exception {
        return projectConfigsService.getConfigInfo(dto, true);
    }
}
